//
//  ShoppingJifenViewController.m
//  HaoDeCaiFu
//
//  Created by 物联信息中心 on 2018/1/9.
//  Copyright © 2018年 郑开宏. All rights reserved.
//

#import "ShoppingJifenViewController.h"
#import "ShouruTableViewController.h"
#import "UIImageView+WebCache.h"

@interface ShoppingJifenViewController ()
@property (weak, nonatomic) IBOutlet UIScrollView *mainScrollView;
@property(nonatomic,assign)NSInteger myJifen;
@end

@implementation ShoppingJifenViewController
-(void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBarHidden=YES;
}
-(void)viewDidDisappear:(BOOL)animated
{
    self.navigationController.navigationBarHidden=NO;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    
    UIScrollView*mainScrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, -20, screenWidth, screenHeight+20)];
    mainScrollView.backgroundColor=[UIColor whiteColor];
    [self.view addSubview:mainScrollView];
    
    UIImage*bgImage=[UIImage imageNamed:@"walletbg"];
    
    UIImageView*imageView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, screenWidth, screenWidth/bgImage.size.width*bgImage.size.height-40)];
    imageView.image=bgImage;
    [mainScrollView addSubview:imageView];
    
    
    UILabel*myJifenLable=[[UILabel alloc]initWithFrame:CGRectMake(0, W_RATIO(200), screenWidth, 40)];
    myJifenLable.text=@"我的积分";
    myJifenLable.textColor=[UIColor whiteColor];
    myJifenLable.textAlignment=1;
    myJifenLable.font=[UIFont systemFontOfSize:17];
    [mainScrollView addSubview:myJifenLable];
    
    
    UILabel*JifenNumLable=[[UILabel alloc]initWithFrame:CGRectMake(0,myJifenLable.bottom+W_RATIO(50), screenWidth, 40)];
    JifenNumLable.text=@"875";
    self.jifenLable=JifenNumLable; 
    JifenNumLable.textColor=[UIColor whiteColor];
    JifenNumLable.textAlignment=1;
    JifenNumLable.font=[UIFont systemFontOfSize:32];
    [mainScrollView addSubview:JifenNumLable];
    
   
    UILabel*titleLable=[[UILabel alloc]initWithFrame:CGRectMake(120, 30, screenWidth-240, 30)];
    titleLable.text=@"积分详情";
    titleLable.textAlignment=1;
    titleLable.textColor=[UIColor whiteColor];
    [self.view addSubview:titleLable];
    
    UIButton*rightBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    rightBtn.frame=CGRectMake(screenWidth-W_RATIO(150)-10, 30, W_RATIO(150), 30);
    [rightBtn setTitle:@"收支明细" forState:UIControlStateNormal];
    [rightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    rightBtn.titleLabel.font=[UIFont systemFontOfSize:14];
    [rightBtn addTarget:self action:@selector(rightBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:rightBtn];
    
    
    UIButton*backBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame=CGRectMake(10, 30, 30, 30);
    [backBtn setImage:[UIImage imageNamed:@"icon_back"] forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(backBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:backBtn];
    
    UIImageView*bigImageView=[[UIImageView alloc]initWithFrame:CGRectMake(30, imageView.bottom+20, screenWidth-60, 800)];
    bigImageView.backgroundColor=ZKcolor(240, 240, 240);
    [mainScrollView addSubview:bigImageView];
    
    [self getMyjifen];
    [bigImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/img_app/jf_readme.png",KIpAddress]] placeholderImage:[UIImage imageNamed:@""] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        bigImageView.image=image;
        bigImageView.frame=CGRectMake(0, imageView.bottom+20, screenWidth, screenWidth/image.size.width*image.size.height);
        mainScrollView.contentSize=CGSizeMake(screenWidth, bigImageView.height+imageView.height+50);
    }];
}

-(void)backBtnClick
{
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)rightBtnClick:(UIButton*)btn
{
    ShouruTableViewController*vc=[[ShouruTableViewController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}

-(void)getMyjifen
{
    
    [SVProgressHUD show];

    [HttpRequest sendSelfGetRequestWithURL:@"api/Credits" WithParamets:nil success:^(id result) {
        
       
        
        if ([result[@"code"] isEqual:@1]) {
            
            self.jifenLable.text=[NSString stringWithFormat:@"%@",result[@"result"]];
            [SVProgressHUD dismiss];
        }else{
            [SVProgressHUD showInfoWithStatus:result[@"msg"]];
        }
    } failure:^(NSError *errer) {
        [SVProgressHUD showErrorWithStatus:@"服务器错误"];
        [SVProgressHUD dismissWithDelay:1.0];
        
        
    }];
    
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
